package com.jwthhealth_pub.old.sportfitness.view.adapter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.sportfitness.module.SprotCourseDescribeModule;
import com.jwthhealth_pub.old.sportfitness.view.SprotCourseInfoSummaryAcitivty;

import java.util.List;

/**
 * Created by Administrator on 2017/1/5.
 */
public class SportcourseSummaryAdapter extends RecyclerView.Adapter {

    SprotCourseInfoSummaryAcitivty acitivty;
    List<SprotCourseDescribeModule.DataBean.DescBean> list;

    public SportcourseSummaryAdapter(SprotCourseInfoSummaryAcitivty sprotCourseInfoSummaryAcitivty, List<SprotCourseDescribeModule.DataBean.DescBean> desc) {
        this.acitivty = sprotCourseInfoSummaryAcitivty;
        this.list = desc;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(acitivty, R.layout.item_sport_course_info_describe, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        SprotCourseDescribeModule.DataBean.DescBean descBean = list.get(position);
        viewHolder.title.setText(descBean.getName());
        viewHolder.rl.setLayoutManager(new LinearLayoutManager(acitivty));
        viewHolder.rl.setAdapter(new InnerAdatper(acitivty, descBean.getDesc()));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        TextView title;
        RecyclerView rl;

        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.head_title);
            rl = (RecyclerView) itemView.findViewById(R.id.body_item_rv);
        }
    }

    private class InnerAdatper extends RecyclerView.Adapter {

        List<String> list;
        SprotCourseInfoSummaryAcitivty mAcitivty;

        public InnerAdatper(SprotCourseInfoSummaryAcitivty acitivty, List<String> desc) {
            this.mAcitivty = acitivty;
            list = desc;
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = View.inflate(mAcitivty, R.layout.item_sport_temp_inner, null);
            return new ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            String s = list.get(position);
            ViewHolder viewHolder = (ViewHolder) holder;
            viewHolder.text.setText(s);
        }

        @Override
        public int getItemCount() {
            return list.size();
        }

        class ViewHolder extends RecyclerView.ViewHolder{

            TextView text;

            public ViewHolder(View itemView) {
                super(itemView);
                text = (TextView) itemView.findViewById(R.id.text);
            }
        }
    }
}
